package com.unknowpupil.design.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: <p>
 * 这个很重要，如果没有就玩不起来。
 * FlyweightFactory享元工厂类
 * k : v
 * </p>
 * @Author: <a> w10g </a>
 * @CreateDate: Create in 2020/4/28 11:09
 * @Classname: ChessFlyWeightFactory
 * @Version: 1.0
 */
public class ChessFlyWeightFactory {
    /**
     * 享元池
     */
    private static Map<String, ChessFlyWeight> map = new HashMap<>();

    public static ChessFlyWeight getChess(String color) {
        if (map.get(color) != null) {
            return map.get(color);
        } else {
            ChessFlyWeight cfw = new ConcreteChess(color);
            map.put(color, cfw);
            return cfw;
        }
    }
}
